#include "gweapon.h"

void gweapon::InitGuaJie()
{
	D3DXFRAME_EX *pGuaJieFrame = pFrameRoot -> Find("guajie");
	if (!pGuaJieFrame)
	{
		dprintf("find guajie frame error\n");
		return;
	}

	while (pGuaJieFrame -> pFrameFirstChild)
	{
		pGuaJieFrame = (D3DXFRAME_EX *)(pGuaJieFrame -> pFrameFirstChild);
	}

	if (pGuaJieFrame -> pMeshContainer)
	{
		pGuaJieMeshContainer = (D3DXMESHCONTAINER_EX *)(pGuaJieFrame -> pMeshContainer);
	}
	else
	{
		dprintf("find guajie mesh error\n");
	}
}

void gweapon::CalGuaJieTransToZero()
{
	struct TriangleDef GJObjTriangle; 
	GenSortPoints(GetGuaJieMeshContainer() -> pMesh, GJObjTriangle.Points);

	GuaJieTransToZero = OriginPosTrans(GJObjTriangle.Points);
}

D3DXMATRIX *gweapon::GetGuaJieTransToZero()
{
	return &GuaJieTransToZero;
}

void gweapon::Load(const char *FileName, IDirect3DDevice9 *pDevice, const char *TexturePath)
{
	gobject::Load(FileName, pDevice, TexturePath);

	pFrameRoot -> CalculateCombined();
	pMeshRoot -> CalculateLocalPos();

	InitGuaJie();
	CalGuaJieTransToZero();
}

D3DXMESHCONTAINER_EX *gweapon::GetGuaJieMeshContainer()
{
	return pGuaJieMeshContainer;
}

